# @Author: Eric Ito
# @Date: 1/26/2009
# @Name: Project Euler Problem 17

"""
If the numbers 1 to 5 are written out in words: one, two, three, four, five,
then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.

If all the numbers from 1 to 1000 (one thousand) inclusive were written out
in words, how many letters would be used?
"""

DICT = {1:"one",
        2:"two",
        3:"three",
        4:"four",
        5:"five",
        6:"six",
        7:"seven",
        8:"eight",
        9:"nine",
        10:"ten",
        11:"eleven",
        12:"twelve",
        13:"thirteen",
        14:"fourteen",
        15:"fifteen",
        16:"sixteen",
        17:"seventeen",
        18:"eighteen",
        19:"nineteen",
        20:"twenty",
        30:"thirty",
        40:"forty",
        50:"fifty",
        60:"sixty",
        70:"seventy",
        80:"eighty",
        90:"ninety",
        100:"onehundred",
        200:"twohundred",
        300:"threehundred",
        400:"fourhundred",
        500:"fivehundred",
        600:"sixhundred",
        700:"sevenhundred",
        800:"eighthundred",
        900:"ninehundred",
        1000:"onethousand",
        }


def countLetters(num):
    if num <= 20:
        return str(DICT[num])
    elif num % 10 == 0 and num < 100:
        return DICT[num]
    elif num % 100 == 0:
        return DICT[num]
    elif num % 1000 == 0:
        return DICT[num]
    elif num > 20 and num < 100:
        return DICT[num/10*10] + countLetters(num%10)
    else:
        return DICT[num/100*100] + "and" + countLetters(num%100)

def main():
    total = ""
    for i in range(1,1001):
        total += countLetters(i)
        #print i,total
    print len(total)

if __name__ == "__main__":
    main()
